#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
//    QPushButton* bt = new QPushButton(this);
//    bt->setText("按钮");
//    bt->move(250,250);
//    //创建图标对象
//    QIcon icon(":/1.jpg");
//    //设置图标
//    bt->setIcon(icon);
//    //设置图标尺寸
//    bt->setIconSize(QSize(50,50));

    QIcon icon_target(":/image/1.jpg");
    QIcon icon_up(":/image/up.png");
    QIcon icon_down(":/image/down.png");
    QIcon icon_left(":/image/left-arrow.png");
    QIcon icon_right(":/image/right.png");

    ui->pushButton_target->setIcon(icon_target);
    ui->pushButton_target->setIconSize(QSize(30,30));

    ui->pushButton_up->setIcon(icon_up);
    ui->pushButton_up->setIconSize(QSize(50,50));

    ui->pushButton_down->setIcon(icon_down);
    ui->pushButton_down->setIconSize(QSize(50,50));

    ui->pushButton_left->setIcon(icon_left);
    ui->pushButton_left->setIconSize(QSize(50,50));

    ui->pushButton_right->setIcon(icon_right);
    ui->pushButton_right->setIconSize(QSize(50,50));

//    ui->pushButton_up->setShortcut(QKeySequence("w"));
//    ui->pushButton_down->setShortcut(QKeySequence("s"));
//    ui->pushButton_left->setShortcut(QKeySequence("a"));
//    ui->pushButton_right->setShortcut(QKeySequence("d"));

    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);

    ui->pushButton_up->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
    ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));
    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    //获取位置
    QRect rect = ui->pushButton_target->geometry();

    ui->pushButton_target->setGeometry(rect.x(),rect.y()-10,rect.width(),rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    //获取位置
    QRect rect = ui->pushButton_target->geometry();

    ui->pushButton_target->setGeometry(rect.x()-10,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    //获取位置
    QRect rect = ui->pushButton_target->geometry();

    ui->pushButton_target->setGeometry(rect.x(),rect.y()+10,rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    //获取位置
    QRect rect = ui->pushButton_target->geometry();

    ui->pushButton_target->setGeometry(rect.x()+10,rect.y(),rect.width(),rect.height());
}
